package com.lm.batch.component;

import org.springframework.batch.core.Job;
import org.springframework.batch.core.JobExecution;
import org.springframework.batch.core.JobParameters;
import org.springframework.batch.core.launch.JobLauncher;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;

@Component
public class JobRunner implements CommandLineRunner {

    private final JobLauncher jobLauncher;
    private final Job importCustomerJob;

    public JobRunner(JobLauncher jobLauncher, Job importCustomerJob) {
        this.jobLauncher = jobLauncher;
        this.importCustomerJob = importCustomerJob;
    }

    @Override
    public void run(String... args) throws Exception {
        JobExecution execution = jobLauncher.run(importCustomerJob, new JobParameters());
        System.out.println("Job Status: " + execution.getStatus());
    }
}